package com.bdqn.t313.cglibdynamicproxy;

import net.sf.cglib.proxy.Enhancer;

public class IntermediaryCglibProxyFactory {

    private static IntermediaryMethodInterceptor callback = new IntermediaryMethodInterceptor();

    /**
     * 工厂方法创建代理对象
     * @param target
     * @param <T>
     * @return
     */
    public static <T> T create(Class<T> target){

        Enhancer enhancer = new Enhancer();
        enhancer.setCallback(callback);
        enhancer.setSuperclass(target);
        return (T) enhancer.create();
    }
}
